home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / c / appsource.lha / APlusPlus / TESTPRGS / intuition / Listview_test.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-29  |  6.4 KB  |  203 lines

  1. /******************************************************************************
  2.  *
  3.  *    $Source: apphome:RCS/testprgs/intuition/Listview_test.cxx,v $
  4.  *
  5.  *    Demo for the A++ Library
  6.  *    Copyright (C) 1994 by Armin Vogt, EMail: armin@uni-paderborn.de
  7.  *
  8.  *    $Revision: 1.6 $
  9.  *    $Date: 1994/07/23 19:15:41 $
  10.  *    $Author: Armin_Vogt $
  11.  *
  12.  ******************************************************************************/
  13.  
  14.  
  15. #include <APlusPlus/exec/SignalResponder.h>
  16. #include <APlusPlus/intuition/GWindow.h>
  17. #include <APlusPlus/graphics/GBorder.h>
  18. #include <APlusPlus/gadtools/GT_Scroller.h>
  19. #include <APlusPlus/gadtools/GT_Listview.h>
  20. #include <APlusPlus/graphics/AutoDrawArea.h>
  21. #include <APlusPlus/intuition/IntuiMessageC.h>
  22.  
  23.  
  24. #include <stdio.h>
  25.  
  26. extern "C" {
  27. #include <dos/dos.h>
  28. }
  29.  
  30.  
  31. volatile static char rcs_id[] = "$Id: Listview_test.cxx,v 1.6 1994/07/23 19:15:41 Armin_Vogt Exp Armin_Vogt $";
  32.  
  33.  
  34.  
  35. // a CTRL-C signal responder from the example in the docs
  36. class MySRSP : public SignalResponder
  37. {
  38.    private:
  39.       BOOL running;  // indicates a received user break to object users
  40.    public:
  41.       MySRSP() : SignalResponder(SIGBREAKB_CTRL_C,0)
  42.       { running = TRUE; }
  43.       ~MySRSP() {}   // NEVER FORGET DO DEFINE EVEN AN EMPTY DESTRUCTOR WITH SASC 6.51. THIS IS A KNOWN BUG!!
  44.  
  45.       //  overload the virtual 'signal received' action callback method.
  46.       void actionCallback()
  47.       {
  48.          puts("**Break\n");
  49.          running = FALSE;  // end WaitSignal loop
  50.       }
  51.  
  52.       // object users can check with this method wether a user break has occurred
  53.       BOOL hasNotOccured() { return running==TRUE; }
  54. };
  55.  
  56.  
  57.  
  58.  
  59. // derive GWindow and add your specific message actions
  60. class MyWindow : public GWindow
  61. {
  62.    private:
  63.       BOOL running;
  64.    public:
  65.       MyWindow(OWNER,AttrList& attrs) : GWindow(owner,attrs)
  66.       {
  67.          if (Ok())   // always check for the correct execution of all base class constructors
  68.          {
  69.             // It is necessary to announce those messages codes this Window class awaits
  70.             // that are not already preset for WindowCV to the WindowCV base class.
  71.             modifyIDCMP(CLASS_ACTIVEWINDOW);
  72.             running = TRUE;
  73.          }
  74.          else running = TRUE;
  75.       }
  76.  
  77.       ~MyWindow() {}
  78.  
  79.  
  80.       void On_CLOSEWINDOW(const IntuiMessageC *msg)
  81.       {
  82.          puts("CLOSEWINDOW.\n");
  83.          running = FALSE;
  84.       }
  85.       void On_ACTIVEWINDOW(const IntuiMessageC *msg)
  86.       {
  87.          ULONG dummy = 0;
  88.          printf("%s is ACTIVE.\n",getAttribute(WA_Title,dummy));
  89.       }
  90.       void On_SIZEVERIFY(const IntuiMessageC *msg)
  91.       {
  92.          puts("SIZEVERIFY. \n");
  93.       }
  94.       void handleIntuiMsg(const IntuiMessageC* imsg)
  95.       {
  96.          switch (imsg->getClass())
  97.          {
  98.             case CLASS_CLOSEWINDOW :
  99.                On_CLOSEWINDOW(imsg); break;
  100.             case CLASS_ACTIVEWINDOW :
  101.                On_ACTIVEWINDOW(imsg); break;
  102.             case CLASS_SIZEVERIFY :
  103.                On_SIZEVERIFY(imsg); break;
  104.          }
  105.          
  106.          GWindow::handleIntuiMsg(imsg);   
  107.          // DO NOT FORGET to hand each message over to the subclass!
  108.       }
  109.  
  110.       BOOL isNotClosed() { return running==TRUE; }
  111. };
  112.  
  113.  
  114.  
  115. void APPmain(int argc,char* argv[])
  116. {
  117.    MySRSP userBreak;
  118.  
  119.    NeXTBorder background((UBYTE*)"diamond.font",12);
  120.  
  121.    MyWindow *mainWindow = new MyWindow(OWNER_NULL,
  122.    AttrList(   WA_Title,(UBYTE*)"WindowC - close this to stop.",
  123.       WA_Width,300,
  124.       WA_Height,150,
  125.       WA_MinHeight,60,
  126.       WA_MinWidth,100,
  127.       WA_MaxHeight,1000,
  128.       WA_MaxWidth,1000,
  129.       GOB_BorderObj(&background),
  130.       GOB_BackgroundColor,4,
  131.       GOB_BorderTitle, (UBYTE*)" GT_Listview & GT_Scroller ",
  132.       TAG_END) );
  133.  
  134.  
  135.    ListC labels;
  136.    #define LABEL_CNT (4*6)
  137.  
  138.  
  139.    // create a sufficient number of NodeC objects that hold the strings as names
  140.    NodeC lnode[LABEL_CNT]= {
  141.       (UBYTE*)"This ", (UBYTE*)"is ", (UBYTE*)"a ", (UBYTE*)"letter", (UBYTE*)"for", (UBYTE*)"you.",
  142.       (UBYTE*)"Use the ", (UBYTE*)"Scroller gadget", (UBYTE*)"on the right", (UBYTE*)" to scroll ", (UBYTE*)"through ", (UBYTE*)" the entry list..",
  143.       (UBYTE*)"Date 07/17/94", (UBYTE*)" by Armin Vogt", (UBYTE*)"You see a GT_Scroller ", (UBYTE*)"connected", (UBYTE*)"with a", (UBYTE*)"GT_Listview.",
  144.       (UBYTE*)"This", (UBYTE*)"is", (UBYTE*)"only", (UBYTE*)"a simple example.", (UBYTE*)"But take a look", (UBYTE*)"at the code.."
  145.       };
  146.    /* IF YOU DO NOT CAST THE STRINGS INTO (UBYTE*), both SAS and GCC seem not to terminate,
  147.     * at least with 6MB RAM!?
  148.     */
  149.  
  150.    // add the created nodes to the ListC object
  151.    for (int i=LABEL_CNT-1;i>=0; i--)
  152.       labels.addHead(&lnode[i]);
  153.  
  154.  
  155.    GT_Listview *listView = new GT_Listview(mainWindow,
  156.    AttrList(   GOB_LeftFromLeftOfParent,     3,
  157.                GOB_TopFromTopOfParent,       3,
  158.                GOB_RightFromRightOfParent,   -40,
  159.                GOB_BottomFromBottomOfParent, -3,
  160.                GA_Immediate,  TRUE,
  161.                GA_RelVerify,  TRUE,
  162.                GTLV_Top,   1,                      // initialise with 1
  163.                GTLV_Labels,         &labels,       // the ListC object is compatible to a List structure
  164.                GTLV_ShowSelected,   NULL,
  165.                LAYOUTA_Spacing,     2,
  166.                TAG_END) );
  167.  
  168.  
  169.    GT_Scroller *scroller = new GT_Scroller(mainWindow,
  170.    AttrList(   GOB_LeftFromRightOfPred,   5,
  171.                GOB_TopFromTopOfPred,      0,
  172.                GOB_RightFromRightOfParent,-5,
  173.                GOB_BottomFromBottomOfPred, 0,
  174. /*      GA_Immediate,TRUE,*/
  175.                GA_RelVerify,  TRUE,
  176.                PGA_Freedom,   LORIENT_VERT,
  177.  
  178.                CONSTRAINT( GTSC_Top, listView, GTLV_Top),   // initialise with GTLV_Top (=1)
  179. /* This constraint doesn't make sense since Listview does not report about scroll movements */
  180.  
  181.                GTSC_Total,    LABEL_CNT,
  182.                GTSC_Visible,  1,
  183.                GTSC_Arrows,   16,
  184.                GT_IDCMP,      SLIDERIDCMP,
  185.                TAG_END) );
  186.  
  187.    // GTLV_Top is initialised from GTSC_Top, which has been initialised from GTLV_Top before
  188.    // ==> GTLV_Top remains 1
  189.    listView->setAttributes(AttrList(CONSTRAINT(GTLV_Top,scroller,GTSC_Top),TAG_END));
  190.  
  191.    mainWindow->refreshGList();      // display objects
  192.  
  193.    /* As soon as the mainWindow deletes itself after having received CLASS_CLOSEWINDOW
  194.     * the loop terminates since the Ok() check within APPOK(mainWindow) fails to be TRUE.
  195.     */
  196.    while (userBreak.hasNotOccured() && APPOK(mainWindow) && mainWindow->isNotClosed())
  197.    {
  198.       SignalResponder::WaitSignal();
  199.    }
  200.  
  201.    puts("cleaned up. goodbye.\n");
  202. }
  203.